<?php

namespace App\Http\Controllers;

use App\Models\Record;
use Illuminate\Http\Request;
use Carbon\Carbon;
use App\Http\Resources\Record as RecordResource;

class TrendController extends Controller
{
    //
    public function index(Request $request){
        $department_id = $request->department_id;

        $start = now()->subYear(2);
        $end = now();

        $monthRecords = Record::where('department_id','=',$department_id)->whereBetween('record_date', [$start, $end])->orderBy('record_date','desc')->get();

        return RecordResource::collection($monthRecords);

    }
}
